package com.hdey.service.max.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdey.mapper.heng.UserMapper;
import com.hdey.mapper.max.TbUscStockMapper;
import com.hdey.pojo.heng.TbUscUser;
import com.hdey.pojo.max.TbUscStock;
import com.hdey.service.max.TbUscStockSvs;
import com.hdey.vo.StockVo;
import com.hdey.vo.StockVoForSearch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@Service("tbUscStockSvs")
@Transactional
@Slf4j
public class TbUscStockSvsImpl extends ServiceImpl<TbUscStockMapper, TbUscStock> implements TbUscStockSvs {

    @Resource
    private TbUscStockMapper stockMapper;

    @Override
    public List<StockVo> getStock(StockVoForSearch stock) {
        System.out.println(stock.toString());
        List<StockVo> list = stockMapper.getStock(stock.getCgName(), stock.getCgCode(), stock.getBranchCode(), stock.getWarehousId());
        //list.forEach(System.out::println);
        return list;
    }

    @Override
    public int updateStockAmount(TbUscStock stock) {
        int result = stockMapper.updateStockAmount(stock.getStockMasterId(), stock.getAmount());
        return result;
    }

    @Override
    public TbUscStock countId(Integer warehousId, Integer dictionaryId) {
        return stockMapper.countId(warehousId,dictionaryId);
    }

    @Override
    public int updateAmount(TbUscStock tbUscStock) {
        return stockMapper.updateById(tbUscStock);
    }

    @Override
    public int add(TbUscStock tbUscStock) {
        tbUscStock.setCreateBy("张三");
        tbUscStock.setCreateDate(LocalDate.now());
        return stockMapper.insert(tbUscStock);
    }
}
